<template>
  <div>
    <h3>消息发布者</h3>
    <input type="text" v-model="msg">
    <p><b>待发布消息：</b>{{ msg }}</p>

    <button @click="publish">发布数据</button>
  </div>
</template>

<script>
// 引入消息订阅与发布
import pubsub from 'pubsub-js'
export default {
  // 消息发送者
  name: 'MyPublish',
  data() {
    return {
      msg: ''
    }
  },
  methods: {
    publish() {
      pubsub.publish('mypublisher', this.msg)
    }
  }
}
</script>

<style scoped>
</style>